package com.saileijieji.mymvp.dialog;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.saileijieji.mymvp.R;
import com.saileijieji.mymvp.bean.TypeSelectBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import mlxy.utils.S;

public abstract class PollingzhanshiDialog extends CenterDialog {


    Context mContext;
    @Bind(R.id.mrecler)
    RecyclerView mrecler;
    List<TypeSelectBean.TypeBean> list=new ArrayList<>();
    CouponAdapter adapter;
    public PollingzhanshiDialog(Context context, List<TypeSelectBean.TypeBean> couponItemBeans) {
        super(context, false);
        setContentView(R.layout.dialog_polling_zhanshi);
        ButterKnife.bind(this);
        mContext = context;
        this.list = couponItemBeans;
        adapter=new CouponAdapter();
        mrecler.setLayoutManager(new LinearLayoutManager(mContext));
        mrecler.setAdapter(adapter);
        adapter.setNewData(couponItemBeans);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                dismiss();
                TypeSelectBean.TypeBean bean  = (TypeSelectBean.TypeBean) adapter.getData().get(position);
                String id=bean.getId();
                String name=bean.getName();
                onActionClicked(id,name);
            }
        });

    }

    public abstract void onActionClicked(String id,String name);



    public class CouponAdapter extends BaseQuickAdapter<TypeSelectBean.TypeBean, BaseViewHolder> {
        public CouponAdapter() {
            super(R.layout.item_zhanshi);
        }

        @Override
        protected void convert(BaseViewHolder helper, TypeSelectBean.TypeBean item) {
            helper.setText(R.id.tv,item.getName());
        }
    }

}
